
/**
 * 尾数分组 mantissaGroups
 */
export const FIVE_MANTISSA_GROUPS = [
  [10, 20, 30, 40],
  [1, 11, 21, 31, 41],
  [2, 12, 22, 32, 42],
  [3, 13, 23, 33, 43],
  [4, 14, 24, 34, 44],
  [5, 15, 25, 35, 45],
  [6, 16, 26, 36, 46],
  [7, 17, 27, 37, 47],
  [8, 18, 28, 38, 48],
  [9, 19, 29, 39, 49]
]

/**
 * 顺序递增分组 AscendingGroups
 */
export const FIVE_ASCENDING_GROUPS = [
  [1, 2, 3, 4, 5],
  [6, 7, 8, 9, 10],
  [11, 12, 13, 14, 15],
  [16, 17, 18, 19, 20],
  [21, 22, 23, 24, 25],
  [26, 27, 28, 29, 30],
  [31, 32, 33, 34, 35],
  [36, 37, 38, 39, 40],
  [41, 42, 43, 44, 45],
  [46, 47, 48, 49]
]

/**
 * 质数分组 PrimeGroups
 */
export const FIVE_PRIME_GROUPS = [
  [2, 3, 5, 7, 11], // 质数组1
  [13, 17, 19, 23, 29], // 质数组2
  [31, 37, 41, 43, 47], // 质数组3
  [1, 4, 6, 8, 9], // 非质数组1
  [10, 12, 14, 15, 16], // 非质数组2
  [18, 20, 21, 22, 24], // 非质数组3
  [25, 26, 27, 28, 30], // 非质数组4
  [32, 33, 34, 35, 36], // 非质数组5
  [38, 39, 40, 42, 44], // 非质数组6
  [45, 46, 48, 49] // 非质数组7（4个号码）
]

/**
 * 斐波那契数分组 FibonacciGroups
 * 黄金比例分组
 */
export const FIVE_FIBONACCI_GROUPS = [
  [1, 2, 3, 5, 8], // 斐波那契数列
  [13, 21, 34, 49, 16], // 斐波那契延伸
  [4, 6, 9, 11, 14], // 非斐波那契组1
  [7, 10, 12, 15, 18], // 非斐波那契组2
  [17, 19, 22, 25, 20], // 非斐波那契组3
  [23, 26, 29, 32, 30], // 非斐波那契组4
  [24, 27, 31, 35, 38], // 非斐波那契组5
  [28, 33, 36, 39, 41], // 非斐波那契组6
  [37, 40, 42, 44, 43], // 非斐波那契组7
  [45, 46, 47, 48] // 最后一组（4个号码）
]

/**
 * 差值递增分组 DifferenceGroups
 */
export const FIVE_DIFFERENCE_GROUPS = [
  [1, 2, 4, 7, 11], // 差值1, 2, 3, 4
  [3, 5, 8, 12, 17], // 差值2, 3, 4, 5
  [6, 9, 13, 18, 24], // 差值3, 4, 5, 6
  [10, 14, 19, 25, 32], // 差值4, 5, 6, 7
  [15, 20, 26, 33, 41], // 差值5, 6, 7, 8
  [16, 21, 27, 34, 42], // 差值5, 6, 7, 8
  [22, 28, 35, 43, 49], // 差值6, 7, 8, 9
  [23, 29, 36, 44, 46], // 差值6, 7, 8, 9
  [30, 37, 45, 47, 48], // 差值7, 8, 9, 1
  [38, 39, 40, 31] // 最后一组（4个号码）
]

/**
 * 中心扩展分组 CenterExpansionGroups
 * 中心对称分组
 */
export const FIVE_CENTER_EXPANSION_GROUPS = [
  [23, 24, 25, 26, 27],
  [20, 21, 22, 28, 29],
  [17, 18, 19, 30, 31],
  [14, 15, 16, 32, 33],
  [11, 12, 13, 34, 35],
  [8, 9, 10, 36, 37],
  [5, 6, 7, 38, 39],
  [2, 3, 4, 40, 41],
  [1, 42, 43, 44, 45],
  [46, 47, 48, 49]
]

/**
 * 大中小号分组 LargeMidSmallGroups
 */
export const FIVE_LARGE_MID_SMALL_GROUPS = [
  [1, 2, 17, 18, 34],
  [3, 4, 19, 20, 35],
  [5, 6, 21, 22, 36],
  [7, 8, 23, 24, 37],
  [9, 10, 25, 26, 38],
  [11, 12, 27, 28, 39],
  [13, 14, 29, 30, 40],
  [15, 16, 31, 32, 41],
  [33, 42, 43, 44, 45],
  [46, 47, 48, 49]
]

/**
 * 四象限分组 QuadrantGroups
 */
export const FIVE_QUADRANT_GROUPS = [
  [1, 2, 13, 25, 37],
  [3, 4, 14, 26, 38],
  [5, 6, 15, 27, 39],
  [7, 8, 16, 28, 40],
  [9, 10, 17, 29, 41],
  [11, 12, 18, 30, 42],
  [19, 20, 31, 36, 43],
  [21, 22, 23, 32, 44],
  [24, 33, 34, 45, 46],
  [35, 47, 48, 49]
]

/**
 * 金字塔分组 PyramidGroups
 */
export const FIVE_PYRAMID_GROUPS = [
  [1, 24, 25, 26, 49],
  [2, 22, 23, 27, 48],
  [3, 20, 21, 28, 47],
  [4, 18, 19, 29, 46],
  [5, 16, 17, 30, 45],
  [6, 14, 15, 31, 44],
  [7, 12, 13, 32, 43],
  [8, 10, 11, 33, 42],
  [9, 34, 35, 40, 41],
  [36, 37, 38, 39]
]

/**
 * 折返分组 foldBackGroups
 * 对称分组
 * 镜像分组
 * 交错分组 CrossingGroups
 */
export const FIVE_FOLD_BACK_GROUPS = [
  [1, 2, 3, 48, 49],
  [4, 5, 6, 46, 47],
  [7, 8, 9, 44, 45],
  [10, 11, 12, 42, 43],
  [13, 14, 15, 40, 41],
  [16, 17, 18, 38, 39],
  [19, 20, 21, 36, 37],
  [22, 23, 24, 34, 35],
  [25, 26, 27, 32, 33],
  [28, 29, 30, 31]
]

/**
 * 跳号分组，跳2 JumpTwoGroups
 * 1. 每隔 2 个号码进行分组
 * 每 2 个号码形成一组，这样每组的号码会打破常规的连续性，分布得更加分散。
 */
export const FIVE_JUMP_TWO_GROUPS = [
  [1, 3, 5, 7, 9],
  [11, 13, 15, 17, 19],
  [21, 23, 25, 27, 29],
  [31, 33, 35, 37, 39],
  [41, 43, 45, 47, 49],
  [2, 4, 6, 8, 10],
  [12, 14, 16, 18, 20],
  [22, 24, 26, 28, 30],
  [32, 34, 36, 38, 40],
  [42, 44, 46, 48]
]

/**
 * 除以3余数分组  ModuloThreeGroups
 */
export const FIVE_MODULO_THREE_GROUPS = [
  [1, 4, 7, 10, 13],
  [2, 5, 8, 11, 14],
  [3, 6, 9, 12, 15],
  [16, 19, 22, 25, 28],
  [17, 20, 23, 26, 29],
  [18, 21, 24, 27, 30],
  [31, 34, 37, 40, 43],
  [32, 35, 38, 41, 44],
  [33, 36, 39, 42, 45],
  [46, 47, 48, 49]
]

/**
 * 跳号分组，跳3 JumpThreeGroups
 */
export const FIVE_JUMP_THREE_GROUPS = [
  [1, 4, 7, 10, 13],
  [16, 19, 22, 25, 28],
  [31, 34, 37, 40, 43],
  [2, 5, 8, 11, 46],
  [14, 17, 20, 23, 26],
  [29, 32, 35, 38, 41],
  [3, 6, 9, 44, 47],
  [12, 15, 18, 21, 24],
  [27, 30, 33, 36, 39],
  [42, 45, 48, 49]
]

/**
 * 跳号分组，跳4
 */
export const FIVE_JUMP_FOUR_GROUPS = [
  [1, 5, 9, 13, 17],
  [21, 25, 29, 33, 37],
  [41, 45, 49, 2, 6],
  [10, 14, 18, 22, 26],
  [30, 34, 38, 42, 46],
  [3, 7, 11, 15, 19],
  [23, 27, 31, 35, 39],
  [43, 47, 4, 8, 12],
  [16, 20, 24, 28, 32],
  [36, 40, 44, 48]
]

/**
 * 跳号分组，跳5
 * 对角线分组
 * 和差分组
 */
export const FIVE_JUMP_FIVE_GROUPS = [
  [1, 6, 11, 16, 21],
  [2, 7, 12, 17, 22],
  [3, 8, 13, 18, 23],
  [4, 9, 14, 19, 24],
  [5, 10, 15, 20, 25],
  // 规律在此
  [26, 31, 36, 41, 46],
  [27, 32, 37, 42, 47],
  [28, 33, 38, 43, 48],
  [29, 34, 39, 44, 49],
  [30, 35, 40, 45]
]

// -------------------------------------------------
// 随机函数
const generateSortedRandomGroups = (existingGroupsSet) => {
  const numbers = Array.from({ length: 49 }, (_, i) => i + 1)

  let groups = []
  let attempts = 0

  // 循环确保生成的每组数据独一无二
  while (groups.length < 10) {
    // 打乱顺序
    const shuffled = numbers.sort(() => Math.random() - 0.5)

    // 分组，并对子数组升序排序
    const tempGroups = []
    for (let i = 0; i < shuffled.length; i += 5) {
      const group = shuffled.slice(i, i + 5).sort((a, b) => a - b)
      tempGroups.push(group)
    }

    // 按子数组首个元素排序
    tempGroups.sort((a, b) => a[0] - b[0])

    // 转换为字符串形式，检查是否重复
    const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
    const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

    if (isUnique) {
      tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr)) // 添加到已存在集合
      groups = tempGroups // 更新当前分组
    }

    attempts++
    if (attempts > 1000) break // 防止死循环
  }

  return groups
}


export const FIVE_GROUP_MAP = {
  FIVE_MANTISSA_GROUPS,
  FIVE_ASCENDING_GROUPS,
  FIVE_PRIME_GROUPS,
  FIVE_FIBONACCI_GROUPS,
  FIVE_DIFFERENCE_GROUPS,
  FIVE_CENTER_EXPANSION_GROUPS,
  FIVE_LARGE_MID_SMALL_GROUPS,
  FIVE_QUADRANT_GROUPS,
  FIVE_PYRAMID_GROUPS,
  FIVE_FOLD_BACK_GROUPS,
  FIVE_JUMP_TWO_GROUPS,
  FIVE_MODULO_THREE_GROUPS,
  FIVE_JUMP_THREE_GROUPS,
  FIVE_JUMP_FOUR_GROUPS,
  FIVE_JUMP_FIVE_GROUPS
}
